<template>
	<view>
		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed" :style="style" :class="bgColor">
				<view class="action" @tap="BackPage" v-show="showback">
					<text :class="backIconClass"></text>
					<slot name="backText"></slot> 
				</view>
				<view class="content" :style="'top:'+StatusBar + 'px'+';color:'+textColor">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar= this.StatusBar;
				var CustomBar= this.CustomBar;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if(this.bgColor.indexOf('#')==0) {
					style = `${style}background-color:${this.bgColor};`;
				} else if(this.bgColor=='') {
					style = `${style}background-color:#F34672;`;
				}
				return style
			},
			showback(){
				
				if(this.isBack || this.isBack=='true') {
					return true;
				} else {
					return false;
				}
			}
		},
		props: {
			bgColor: {
				type: String,
				default: ''
			},
			textColor: {
				type: String,
				default: '#FFFFFF'
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			backIconClass: {
				type: String,
				default: 'cuIcon-back'
			},
			backClicked:{
				type:Function,
				default:null
			}
		},
		methods: {
			BackPage() {
				if(this.backClicked!=null) {
					this.backClicked();
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			}
		}
	}
</script>

<style>
.cu-custom {
	color: #FFFFFF;
}
</style>
